<%@page import="com.bms.entity.User"%>
<%@page import="com.bms.dao.UserDao"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户修改</title>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/js/function.js"></script>
<script type="text/javascript">
	//检测表单中的数据
	function check(form) {
		//为空判断
		if (form.userName.value == "") {
			alert("登录名称不能为空！");
			form.userName.focus();
			return;
		}
		if (form.realName.value == "") {
			alert("真实姓名不能为空！");
			form.realName.focus();
			return;
		}
		if (form.password.value == "") {
			alert("密码不能为空！");
			form.password.focus();
			return;
		}
		if (form.pwd.value == "") {
			alert("确认密码不能为空！");
			form.pwd.focus();
			return;
		}

		//两次密码的值是否一致
		if (form.password.value != form.pwd.value) {
			alert("两次输入密码不相同！");
			form.pwd.focus();
			return;
		}

		//判断密码是否修改了
		/*
			标识位：md5flag
			 判断当前的密码值和原有的密码值是否一致：不一致：md5flag="1"
		 */
		//获取当前密码框的值
		var value = form.password.value;
		console.info(value);

		//获取密码框原来的值
		var defaultValue = form.password.defaultValue;
		console.info(defaultValue);
		if (value != defaultValue) {
			form.md5flag.value = "1";
		}

		//提交表单
		alert("点击刷新");
		window.close();
		form.submit();
		refreshOpener();
		/* //重新刷新打开当前窗口的页面
		opener.location.reload();
		window.close(); */
		//保证数据在页面刷新之间已经保存到数据库中
		//alert("点击刷新！");
		

	}
</script>
</head>
<body>

	<%
		//1、先获取传递过来的id
		String param = (String) request.getParameter("id");

		int id = Integer.valueOf(param);
		//2、拿着id查询数据库
		UserDao dao = new UserDao();
		User userInfo = dao.getUserInfoById(id);
	%>
	<form action="<%=request.getContextPath()%>/userAction"
		name="addUser" method="post">
		<input type="hidden" name="method" value="doEdit">
		<!-- 标识更新谁的数据的 -->
		<input type="hidden" name="id" value="<%=userInfo.getId()%>">
		<!-- 标识密码是否修改的 -->
		<input type="hidden" name="md5flag">
		<table>
			<caption>修改用户</caption>
			<tr>
				<td>登录账户:</td>
				<td><input readonly="readonly" type="text" name="userName"
					value="<%=userInfo.getUserName()%>"></td>
			</tr>
			<tr>
				<td>真实姓名:</td>
				<td><input type="text" name="realName"
					value="<%=userInfo.getRealName()%>"></td>
			</tr>
			<tr>
				<td>登录密码:</td>
				<td><input type="password" name="password"
					value="<%=userInfo.getPassword()%>"></td>
			</tr>
			<tr>
				<td>确认密码:</td>
				<td><input type="password" name="pwd"
					value="<%=userInfo.getPassword()%>"></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><input type="button" value="保存"
					onclick="check(addUser);"> <input type="reset"
					value="重置"></td>
			</tr>
		</table>
	</form>

</body>
</html>